So to me, quick lecture about time or what it is and how we can use it in our games now, um, I believe
I can't remember what topic it was now, but one of the lectures a bit earlier on involved time somewhere.
Um.
Was it game passes?
I'm not sure exactly now forgotten, but one of them had a property where you can see the time something
occurred and it returned in time.
So that is one of the cases where time has been used.
We can have a look at it today and how we can access it in Roblox studio.
So time is used not in just Robot Studio, but in other kind of software and programming languages as
well.
What it is, is a method of computers keep track of time.
So if the time, the time now, for example, um, is in multiple numbers, you obviously got seconds,
hours.
Um, days, weeks, all that other kind of stuff.
Um, for tracking time.
And that's very difficult to, for computers to keep track of.
You've got time zones, you've got, um, daylight saving times, you've got a very number of days and
months.
You've got leap years.
Um, time's very complicated, actually, for computers to try and keep track of.
So, um, instead of having to run complex code and, and be involved in time, time zone changes and
all that kind of stuff, we just use OS time.
Now OS time is just one long number, which basically what it is, is the number of seconds from the
1st of January or midnight on the 1st of January, 1970.
Okay.
That's the number of seconds from that, from that time.
Um, why that date?
I'm not too sure.
Really.
I think it just comes down to the history of programming, I think.
Um, maybe in about 1969.
Then they, um, came up the concept of time, and they decided to launch it at the start of a new year.
But, um, yeah, that's basically where this is from.
So, um, why would we want to use this long number in Roblox studio?
Well, um, we can use it basically.
I mean, the biggest use of it is to time how long things take in in your game, basically.
So if you've got a time trial and you want to see how long it take, you would use OS time.
If you wanted to see how long a player has been playing the game for in total, you would you would
use again OS time because basically, um, well, let's add a script in first to explain this to you
so you can access OS time very easily by getting OS, which is the library of functions relating to
um OS time dot time like this here.
And whenever the script reads this, it will return um, the OS time at that point.
So if I print OS time.
Wait two seconds and then prints us time again.
You'll be able to see a two second difference between those two numbers.
Well, what a two.
A two difference, basically.
There you go.
That's my time there and time there.
Um, so let's say, for example, we wanted to see how long it would take to go from one part to another
part.
So this is, um, part zero.
And this would be part one.
We want to see how long it takes for a player to go from one to the other.
Now there'd be no way of tracking this apart from using time.
You couldn't use a weight because you don't know how long to wait for.
Um, and you could, I guess, count, use fire something which counts and then fire it back.
So I guess you could, but it's just very complicated, really.
And probably not very accurate either.
So, um, let's reference both of these two parts and try this in a bit more of a practical example.
So um, local part zero is equal to his time.
There is equal to game dot workspace dot part zero.
Local part one.
Is eager to gain that workspace.
Part one.
Okay, let's let's give part makes up part zero read.
And this one green.
So we know which way we're going.
So we're starting in the red part and going to the green part.
So part zero dot touched connect function hit.
If hit dot parent.
Colon.
Fine.
First child.
Humanoids.
Then local start time is equal to start time.
So this will be the time that we first started this time trial almost between these two parts.
Then once the second part has been touched.
So part one, um, we can then basically print the current time.
Remember we cut the time.
At this point it will be larger because time will have passed from when we first touched the part.
Zero take away the the start time over here would then give you the number of seconds between that.
Now, because we define this variable in here, we can't use it.
We need to define it above.
Start time is equal to nil.
And then just say.
Like that there.
Okay, so let's try this out.
Let's play the game here and see how long it takes us.
So let's go in.
And one of my clothing isn't loading properly.
We've started it.
And let's go over to here.
And nice.
It's taken us four and five seconds there.
Okay, so that's just one example of using time.
I think it's a really good way for you to keep track of time in your game.
And the calculating the time between two events, I think is the best method of using it, but there
will be other applications of it as well.
Um, so what else was there to do with um, there was one other thing to do with time.
Um, I might just mention which is start date.
This will basically return the date in a string format.
So actual user friendly date.
Why you might want to do this.
Um, I'm not too sure.
Really?
Um.
You could perhaps, um, maybe you have a live event, say, the live events occurring at this at this
time.
And if you print the date just to say this is your date, this is when the event is happening, um,
or something like that.
So it's just a possibility.
If you ever did want to do that, it's just a date.
It's so small.
It's just worth mentioning if you do happen to need it.
Um, but yeah.
So really the library functions, the only time we're going to use it really is when you're looking
for time like that there.
So hopefully, um, that's been another that's been, um, a bit more familiar with you and you're and
you're comfortable with using time.
It has applications in your game.
So it is very useful knowing about.
So yeah have a try out all those things and join me the next lecture.
We are going to have a look at teleport service.